package java6681.lesson01;

import java.util.Objects;

/*
 * 商品
 * */
public class Product6681 {
    private String name;//商品名称

    public Product6681() {

    }

    public Product6681(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    /*重写，只要商品名称相同，就认为两个商品对象是相等的*/
    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (obj == this) return true;
        if (obj instanceof Product6681) {
            Product6681 p = (Product6681) obj;
            return p.name.equals(name);
        }
        return false;
    }

}
/*        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product6681 that = (Product6681) o;
        return Objects.equals(name, that.name);*/
